package io.renren.modules.workjobs.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.utils.CommonBusinessStatus;
import io.renren.modules.workjobs.dao.DeliveryCreateUserPositionDao;
import io.renren.modules.workjobs.dao.WorkJobDao;
import io.renren.modules.workjobs.entity.WorkJobEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigurationPackage;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.workjobs.entity.DeliveryCreateUserPositionEntity;
import io.renren.modules.workjobs.service.DeliveryCreateUserPositionService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 
 *
 * @author nyc
 * @email 2691778746@qq.com
 * @date 2022-03-23 15:28:02
 */
@RestController
@RequestMapping("workjobs/deliverycreateuserposition")
public class DeliveryCreateUserPositionController {
    @Autowired
    private DeliveryCreateUserPositionService deliveryCreateUserPositionService;
    @Autowired
    private DeliveryCreateUserPositionDao deliveryCreateUserPositionDao;


    @Autowired
    private WorkJobDao workJobDao;

    @RequestMapping("/receive-delivery-other-info/{userId}")
    public R receiveDelivery(@PathVariable("userId")String userId){

        /*统计的是投递量*/
        QueryWrapper<DeliveryCreateUserPositionEntity> wrapper = new QueryWrapper();
        wrapper.eq("user_create_position_id",userId);
        List<DeliveryCreateUserPositionEntity> deliveryCreateUserPositionEntities = deliveryCreateUserPositionDao.selectList(wrapper);

        QueryWrapper<WorkJobEntity> workJobEntityWrapper = new QueryWrapper<>();
        workJobEntityWrapper.eq("create_user_id",userId);
        List<WorkJobEntity> workJobEntities = workJobDao.selectList(workJobEntityWrapper);
        /*我创建的职位信息*/


        /*我发布的职位信息*/
        List<WorkJobEntity> myPublishPostitionWorkJobList = workJobEntities.stream().filter(item -> CommonBusinessStatus.POSITION_PUBLISH_HAVE.equals(item.getJobIssueStatus()))
                .collect(Collectors.toList());


        return R.ok().put("deliveryCount",deliveryCreateUserPositionEntities.size())
                .put("createCount",workJobEntities.size())
                .put("publishCount",myPublishPostitionWorkJobList.size());
    }


    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("workjobs:deliverycreateuserposition:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = deliveryCreateUserPositionService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("workjobs:deliverycreateuserposition:info")
    public R info(@PathVariable("id") Long id){
		DeliveryCreateUserPositionEntity deliveryCreateUserPosition = deliveryCreateUserPositionService.getById(id);

        return R.ok().put("deliveryCreateUserPosition", deliveryCreateUserPosition);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("workjobs:deliverycreateuserposition:save")
    public R save(@RequestBody DeliveryCreateUserPositionEntity deliveryCreateUserPosition){
		deliveryCreateUserPositionService.save(deliveryCreateUserPosition);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("workjobs:deliverycreateuserposition:update")
    public R update(@RequestBody DeliveryCreateUserPositionEntity deliveryCreateUserPosition){
		deliveryCreateUserPositionService.updateById(deliveryCreateUserPosition);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("workjobs:deliverycreateuserposition:delete")
    public R delete(@RequestBody Long[] ids){
		deliveryCreateUserPositionService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
